package com.example.demo.common;

import com.example.demo.common.api.SettlementBo;
import com.example.demo.constant.Constant;
import com.example.demo.fruits.Fruits;
import com.example.demo.fruits.factory.FruitFactory;
import com.example.demo.fruits.strategy.Context;
import com.example.demo.fruits.strategy.DisCountStrategyA;
import org.springframework.util.CollectionUtils;

import java.util.List;

public class Settlement {

    public static double settlement(SettlementBo bo){

        List<Fruits> fruitsList = bo.getFruitsList();

        String fullMinusFlag = bo.getFullMinusFlag();

        double totalPrice=0.0;

        if(!CollectionUtils.isEmpty(fruitsList)){
            for(Fruits fruits:fruitsList){
                totalPrice+=fruits.sum();
            }
            if(Constant.FULL_MINUS_1.equals(fullMinusFlag)){
                Context context=new Context(new DisCountStrategyA());
                totalPrice=context.cost(totalPrice);
            }
        }

        return totalPrice;
    }

}
